home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / tool / vdgear / src / grp.c < prev    next >
Text File  |  1994-11-16  |  9KB  |  403 lines

  1. /*
  2.  *    VIDEO GEAR
  3.  *    "grp.c"
  4.  *    by Good-Chy
  5.  */
  6.  
  7. #include    "video.h"
  8.  
  9. FILE    *fp;
  10. char    *tif_p;
  11. int    tif_flag, tif_x, tif_y;
  12.  
  13. void    mos_init()
  14.     {
  15.     MOS_resolution(0,3);
  16.     MOS_writePage(0);
  17.     MOS_horizon(0,639);
  18.     MOS_vertical(0,479);
  19.     setmos(81);
  20.     MOS_disp(1);
  21.     }
  22.  
  23. void    screen1()
  24.     {
  25.     EGB_init(egb_work,1536);
  26.     EGB_resolution(egb_work,0, 3);        /* 16 色 */
  27.     EGB_resolution(egb_work,1,10);        /* 32k色 */
  28.     EGB_resolutionRam(egb_work,0x80, 4,640,480,mvram1);    /* 仮想画面1 */
  29.     EGB_resolutionRam(egb_work,0x81,16,320,240,mvram2);    /* 仮想画面2 */
  30.  
  31.     EGB_displayPage(egb_work,0,3);        /* page0を手前に */
  32.     EGB_color(egb_work,1,0);            /* 背景色を0 */
  33.  
  34.     EGB_writePage(egb_work,0);            /* page0の設定 */
  35.     EGB_clearScreen(egb_work);
  36.     EGB_displayStart(egb_work,2,1,1);        /* 倍率1*1 */
  37.     EGB_displayStart(egb_work,3,640,480);    /* 大きさ */
  38.  
  39.     EGB_writePage(egb_work,1);            /* page1の設定 */
  40.     EGB_clearScreen(egb_work);
  41.     EGB_displayStart(egb_work,2,2,2);        /* 倍率2*2 */
  42.     EGB_displayStart(egb_work,3,320,240);    /* 大きさ */
  43.  
  44.     EGB_writePage(egb_work,0);
  45.     }
  46.  
  47. void    main_screen_load()
  48.     {
  49.     char    *p;
  50.     p = tiff_load("vdgear.sc2");            /* ウィンドウデ-タ読み込み */
  51.     EGB_writePage(egb_work,0x80);
  52.     put_vram((p+6),0,0,WORD(p+0),WORD(p+2));
  53.     free(p);
  54.     p = tiff_load("vdgear.sc3");            /* 32kデ-タ読み込み */
  55.     EGB_writePage(egb_work,0x81);
  56.     put_vram((p+6),0,0,WORD(p+0),WORD(p+2));
  57.     free(p);
  58.     p = tiff_load("vdgear.sc1");            /* メイン画面読み込み */
  59.     TIFF_getPal(pal_buff);
  60.     EGB_palette(egb_work, 0, pal_buff);
  61.     EGB_writePage(egb_work,0);
  62.     put_vram((p+6),0,0,WORD(p+0),WORD(p+2));
  63.     free(p);
  64.  
  65.     sprint("V2.1b 1993 by Good-Chy",438,458,15,0,16,16,9);
  66.     }
  67.  
  68. void    screen2()
  69.     {
  70.     MOS_disp(0);
  71.  
  72.     EGB_resolution(egb_work,0,11);        /* 32k色 */
  73.     EGB_resolution(egb_work,1,11);        /* 32k色 */
  74.     EGB_resolutionRam(egb_work,0x80,16,320,240,mvram2);    /* 仮想画面1 */
  75.  
  76.     EGB_displayPage(egb_work,0,3);        /* page0を手前に */
  77.     EGB_color(egb_work,1,0x8000);            /* 背景色を0x8000 */
  78.  
  79.     EGB_writePage(egb_work,0);            /* page0の設定 */
  80.     EGB_clearScreen(egb_work);
  81.     EGB_displayStart(egb_work,2,4,1);        /* 倍率4*1 */
  82.     EGB_displayStart(egb_work,3,320,240);    /* 大きさ */
  83.  
  84.     EGB_writePage(egb_work,1);            /* page1の設定 */
  85.     EGB_clearScreen(egb_work);
  86.     EGB_displayStart(egb_work,2,4,1);        /* 倍率4*1 */
  87.     EGB_displayStart(egb_work,3,320,240);    /* 大きさ */
  88.  
  89.     EGB_writePage(egb_work,0);
  90.     }
  91.  
  92. int    read_data(char *bp, int size)        /* tiffをファイルから読み込む */
  93.     {
  94.     if (fread(bp, 1, size, fp) != size ) 
  95.         { return -1; }
  96.     return 0;
  97.     }
  98.  
  99. int    put_data(char *buf, int lofs, int lines )    /* tiffをメモリに蓄える */
  100.     {
  101.     int    i, j, sx;
  102.     if (tif_flag == 16)            /* 16色 */
  103.         { sx = tif_x/2; }
  104.     else                        /* 32k色 */
  105.         { sx = tif_x*2; }
  106.  
  107.  
  108.     for (i=0 ; i<lines ; i++)
  109.         {
  110.         for (j=0 ; j<sx ; j++)
  111.             {
  112.             *(tif_p+(i+lofs)*sx+j + 6) = *(buf+i*sx+j);
  113.             }
  114.         }
  115.     return 0;
  116.     }
  117.  
  118. char    *tiff_load(char *file_name)    
  119.     {
  120.     char *load_buff, *save_buff, *comp_buff;
  121.     int load_buf_size, save_buf_size, bit_pix, line_size;
  122.     int comp,fill;
  123.     long strip, clut, width;
  124.     err = 0;
  125.  
  126.     MOS_disp(0);                        /* マウスを時計に */
  127.     setmos(82);
  128.     MOS_disp(1);
  129.  
  130.     load_buf_size = 1024*150;                /* バッファサイズ */
  131.     save_buf_size = 1024*150;
  132.     load_buff = malloc( load_buf_size );        /* ロードバッファ */
  133.     save_buff = malloc( save_buf_size );        /* 展開バッファ */
  134.     comp_buff = malloc( DECOMP_WORK_SIZE );        /* 圧縮展開用ワーク */
  135.  
  136.     if ((fp = fopen(file_name, "rb")) == NULL)    /* ファイルオープン */
  137.         { err = 1;    return NULL; }
  138.  
  139.     fread(load_buff, 1, load_buf_size, fp);        /* 最初のデータロード */
  140.  
  141.     if (TIFF_getHead(load_buff, load_buf_size)<0)    /* ヘッダの解析 */
  142.         { err = 2;    return NULL; }
  143.  
  144.     if ((bit_pix = TIFF_checkMode(&tif_x,&tif_y,&comp,&fill,&strip,&clut))<0)
  145.         { err = 2;    return NULL; }
  146.  
  147.     if ((bit_pix == 24) || (bit_pix == 8))        /* 1600万色,256色 */
  148.         { err = 3;    return NULL; }
  149.  
  150.     TIFF_setLoadFunc(put_data, read_data);        /* 関数の定義 */
  151.  
  152.     width = tif_x;
  153.     if (bit_pix == 4)
  154.         {
  155.         if (width & 7)    { width += 8 - (width & 7); }
  156.         }
  157.  
  158.     line_size = save_buf_size / ((width * bit_pix + 7)/ 8);
  159.                                     /* バッファに入る行数 */
  160.  
  161.     if (bit_pix == 4)                        /* 16色モ-ド */
  162.         {
  163.         tif_flag = 16;
  164.         tif_p =  malloc((tif_x+8)/8*4*(tif_y+1));
  165.         }
  166.     else                                /* 32k色モ-ド */
  167.         {
  168.         tif_flag = 32;
  169.         tif_p =  malloc((tif_x+1)*2*(tif_y+1));
  170.         }
  171.     WORD(tif_p + 0) = tif_x-1;
  172.     WORD(tif_p + 2) = tif_y-1;
  173.     WORD(tif_p + 4) = bit_pix;
  174.  
  175.                                     /* TIFFデータの読込 */
  176.     TIFF_loadImage(bit_pix, tif_x,tif_y, strip, fill, comp,
  177.                      save_buff, width, line_size, comp_buff);
  178.     
  179.     free(load_buff);
  180.     free(save_buff);
  181.     free(comp_buff);
  182.     fclose(fp);
  183.     MOS_disp(0);                        /* マウスを矢印に */
  184.     setmos(81);
  185.     MOS_disp(1);
  186.  
  187.     return(tif_p);
  188.     }
  189.  
  190. int    write_data(char *buf, long size)
  191.     {
  192.     if (fwrite(buf, 1, size, fp) != size ) 
  193.         { return -1; }
  194.     return 0;
  195.     }
  196.  
  197. int    get_data(char *buf, int ofs, int lines)
  198.     {
  199.     int    i,j;
  200.  
  201.     for (i=0 ; i<lines ; i++)
  202.         {
  203.         for (j=0 ; j<tif_x*2 ; j++)
  204.             {
  205.             *(buf+i*tif_x*2+j) = *(tif_p+(i+ofs)*tif_x*2+j);
  206.             }
  207.         }
  208.     return 0;
  209.     }
  210.  
  211. void    tiff_save(char *file_name, char *buf, int x, int y)
  212.     {
  213.     char *imag_buff, *save_buff, *comp_buff;
  214.     int imag_buf_size, save_buf_size, line_size;
  215.     long    tiff_size;
  216.     err = 0;
  217.  
  218.     MOS_disp(0);                        /* マウスを時計に */
  219.     setmos(82);
  220.     MOS_disp(1);
  221.  
  222.     imag_buf_size = 1024*150;                /* バッファサイズ */
  223.     save_buf_size = 1024*150;
  224.     imag_buff = malloc( imag_buf_size );        /* イメ-ジバッファ */
  225.     save_buff = malloc( save_buf_size );        /* セ-ブバッファ */
  226.     comp_buff = malloc( COMP_WORK_SIZE );        /* 圧縮展開用ワーク */
  227.     
  228.     if ((fp = fopen(file_name, "wb")) == NULL)    /* ファイルオープン */
  229.         { err = 1; }
  230.  
  231.     fseek(fp,512,0);
  232.     tif_p = buf;
  233.     tif_x = x;
  234.     tif_y = y;
  235.  
  236.     TIFF_setSaveFunc(write_data, get_data);
  237.  
  238.     line_size = imag_buf_size / (x*2);
  239.  
  240.     TIFF_saveImage(16,x,y,5,save_buff,save_buf_size,imag_buff,x,line_size,comp_buff);
  241.  
  242.     tiff_size = ftell(fp)-512;
  243.  
  244.     TIFF_setHead(save_buff,16,x,y,tiff_size,NULL);
  245.     rewind(fp);
  246.     fwrite(save_buff,1,512,fp);
  247.  
  248.     free(imag_buff);
  249.     free(save_buff);
  250.     free(comp_buff);
  251.     fclose(fp);
  252.     MOS_disp(0);                        /* マウスを矢印に */
  253.     setmos(81);
  254.     MOS_disp(1);
  255.     }
  256.  
  257.  
  258. void    sprint(char *str, int  x, int  y, int c1, int c2,
  259.                 int vx, int vy, int sty)
  260.     {
  261.     EGB_textZoom(egb_work,0,vx/2,vy);
  262.     EGB_textZoom(egb_work,1,vx,vy);
  263.     EGB_fontStyle(egb_work,sty);
  264.     EGB_color(egb_work,0,c1);
  265.     EGB_color(egb_work,1,c2);
  266.  
  267.     WORD(para+0) = x;
  268.     WORD(para+2) = y;
  269.     WORD(para+4) = strlen(str);
  270.     strcpy((char *)(para+6),str);
  271.     MOS_disp(0);
  272.     EGB_sjisString(egb_work,para);
  273.     MOS_disp(1);
  274.     }
  275.  
  276. void    sprintusing(int obj, int keta, int x, int y, int c1, int c2,
  277.                      int vx, int vy, int sty)
  278.     {
  279.     char    sstr[10];
  280.     int    i,j;
  281.     i = keta-1;
  282.  
  283.     for (j=0 ; j<9 ; j++)    { sstr[j] = ' '; }
  284.     sstr[keta] = '\0';
  285.  
  286.     while((obj>9) && (i>0))
  287.         {
  288.         sstr[i] = '0' + (obj % 10);
  289.         obj /= 10;
  290.         i--;
  291.         }
  292.         sstr[i] = '0' + obj;
  293.  
  294.     sprint(sstr,x,y,c1,c2,vx,vy,sty);
  295.     }
  296.  
  297. void    box_full(int x1, int y1, int x2, int y2, int c1, int c2, int func)
  298.     {
  299.     EGB_color(egb_work,0,c1);            /* 枠の色 */
  300.     EGB_color(egb_work,2,c2);            /* 中塗り色 */
  301.     EGB_writeMode(egb_work,func);            /* 描写モ-ド */
  302.  
  303.     WORD(para+0) = x1;
  304.     WORD(para+2) = y1;
  305.     WORD(para+4) = x2;
  306.     WORD(para+6) = y2;
  307.     MOS_disp(0);
  308.     EGB_rectangle(egb_work,para);
  309.     MOS_disp(1);
  310.     }
  311.  
  312. char    *get_vram(int flag,int x1, int y1, int x2, int y2)
  313.     {
  314.     char    *p;
  315.  
  316.     if (flag == 16)                        /* 16色モ-ド */
  317.         { p =  malloc((x2-x1+8)/8*4*(y2-y1+1)); }
  318.     else                                /* 32k色モ-ド */
  319.         { p =  malloc((x2-x1+1)*2*(y2-y1+1)); }
  320.  
  321.     EGB_writeMode(egb_work,0);
  322.     DWORD(para+ 0) = (unsigned int)p;
  323.      WORD(para+ 4) = getds();
  324.      WORD(para+ 6) = x1;
  325.      WORD(para+ 8) = y1;
  326.      WORD(para+10) = x2;
  327.      WORD(para+12) = y2;
  328.     MOS_disp(0);
  329.     EGB_getBlock(egb_work, para);
  330.     MOS_disp(1);
  331.     return p;
  332.     }
  333.  
  334. void    put_vram(char *p, int x1, int y1, int x2, int y2)
  335.     {
  336.     EGB_writeMode(egb_work,0);
  337.     DWORD(para+ 0) = (unsigned int)p;
  338.      WORD(para+ 4) = getds();
  339.      WORD(para+ 6) = x1;
  340.      WORD(para+ 8) = y1;
  341.      WORD(para+10) = x2;
  342.      WORD(para+12) = y2;
  343.     MOS_disp(0);
  344.     EGB_putBlock(egb_work, 0, para);
  345.     MOS_disp(1);
  346.     }
  347.  
  348. void    put_vram_zoom(char *p, int x1, int y1, int x2, int y2, int dx, int dy)
  349.     {
  350.     EGB_writeMode(egb_work,0);
  351.     DWORD(para+ 0) = (unsigned int)p;
  352.      WORD(para+ 4) = getds();
  353.      WORD(para+ 6) = x1;
  354.      WORD(para+ 8) = y1;
  355.      WORD(para+10) = x2;
  356.      WORD(para+12) = y2;
  357.      WORD(para+14) = dx;
  358.      WORD(para+16) = dy;
  359.     MOS_disp(0);
  360.     EGB_putBlockZoom(egb_work, 0, para);
  361.     MOS_disp(1);
  362.     }
  363.  
  364. void    scroll(int x1, int y1, int x2, int y2, int vx, int vy)
  365.     {
  366.     WORD(para+0) = x1;
  367.     WORD(para+2) = y1;
  368.     WORD(para+4) = x2;
  369.     WORD(para+6) = y2;
  370.  
  371.     EGB_partScroll(egb_work, 0, vx, vy, para);
  372.     }
  373.  
  374. void    line(int x1, int y1, int x2, int y2, int c1)
  375.     {
  376.     EGB_color(egb_work,0,c1);
  377.     WORD(para+0) = 2;
  378.     WORD(para+2) = x1;
  379.     WORD(para+4) = y1;
  380.     WORD(para+6) = x2;
  381.     WORD(para+8) = y2;
  382.     MOS_disp(0);
  383.     EGB_connect(egb_work,para);
  384.     MOS_disp(1);
  385.     }
  386.  
  387. void    set_palette(int i, char r, char g, char b)
  388.     {
  389.     DWORD(para+ 0) = 1;
  390.     DWORD(para+ 4) = i;
  391.      BYTE(para+ 8) = b;
  392.      BYTE(para+ 9) = r;
  393.      BYTE(para+10) = g;
  394.      BYTE(para+11) = 0;
  395.     EGB_palette(egb_work,1,para);
  396.     }
  397.  
  398. void    wait_vsync()
  399.     {
  400.     DWORD(para+0) = 0;
  401.     EGB_palette(egb_work,1,para);
  402.     }
  403.